package com.mmall.controller.portal;

import com.github.pagehelper.PageInfo;
import com.mmall.common.Const;
import com.mmall.common.ResponseCode;
import com.mmall.common.ServerResponse;
import com.mmall.pojo.User;
import com.mmall.service.IProductService;
import com.mmall.service.IUserService;
import com.mmall.vo.ProductDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @author cg.hu
 * @version 1.0.0
 * @date 2021-09-22 17:18
 * @description
 * @since 1.0.0
 */
@Controller
@RequestMapping("/product/")
public class ProductController {

    @Autowired
    private IProductService iProductService;

    @Autowired
    private IUserService iUserService;

    /**
     * @author cg.hu
     * @version 1.0.0
     * @date 2021-09-23 8:32
     * @description    用户端获取商品详情
     **/
    @RequestMapping(value = "detail.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse getDetail(HttpSession session, Integer productId) {
        // 获取商品详情
        return iProductService.getProductDetail(productId);
    }

    /**
     * @author cg.hu
     * @version 1.0.0
     * @date 2021-09-23 8:35
     * @description    商品分页查询
     **/
    @RequestMapping(value = "list.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<PageInfo> list(@RequestParam(value = "keyWord", required = false) String keyWord,
                                         @RequestParam(value = "orderBy", required = false, defaultValue = "") String orderBy,
                                         @RequestParam(value = "categoryId", required = false) Integer categoryId,
                                         @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "10") int pageSize
                                         ) {

        return iProductService.getProductByKeyWordCategory(keyWord, orderBy, categoryId, pageNum, pageSize);
    }

}
